<template>
  <div class="page">
    <u-navbar>
      <view class="slot-wrap">
        <u-search placeholder="订单编号" v-model="searchForm.orderSn" @search="load" @custom="load"></u-search>
		<div class="drop-list-config" @click="handleClickScreen">
		  <div>
		    筛选
		  </div>
		</div>
      </view>
    </u-navbar>
    <div class="drop-list">
      <div class="drop-list-tab">
        <u-tabs :list="list" active-color="#333" :is-scroll="true" :current="current" @change="changeTabs"></u-tabs>
      </div>
    </div>

    <div class="global-list" v-if="afterSaleData.length != 0">
      <div class="global-item" @click="handleClickSales(item)" v-for="(item,index) in afterSaleData" :key="index">

        <div class="flex global-top-col">
          <div class="global-sn">{{item.sn}}</div>
          <div class="global-orderStatus">{{item.serviceStatus | serviceStatusList}}</div>
        </div>
        <!-- 商品信息 -->
        <div class="flex goods-item">
          <div>
            <u-image width="150" height="150" :src="item.goodsImage" mode="" />
          </div>
          <div class="wes-2 goods-name">{{item.goodsName}}</div>
          <!-- 价格 -->
          <div class="flex goods-right-col">
            <div>x <span>{{item.num}}</span></div>
          </div>
        </div>

        <div class="global-bottom-col flex">
          <div class="global-createTime">{{item.createTime}}</div>
          <div class="global-clientType">用户：{{item.memberName}}</div>
        </div>
        <div class="goods-follow-price">
          申请金额：<span>￥{{item.flowPrice| unitPrice}}</span>
        </div>

      </div>
    </div>

    <popup memberName goodsName date ref="popup" @callback="screened" />

  </div>
</template>

<script>
import { afterSaleOrderPage } from "@/api/order";
import popup from "@/components/m-popup/index";
export default {
  components: {
    popup,
  },
  watch: {
    current(index) {
      let way = ["RETURN_GOODS", "RETURN_MONEY","EXCHANGE_GOODS","REPAIR_GOODS"];
      this.searchForm.serviceType = way[index];
      this.load()
    },
  },
  data() {
    return {
      afterSaleData: [], //售后列表
      current: 0,
      searchForm: {
        // 搜索框初始化对象
        pageNumber: 1, // 当前页数
        pageSize: 10, // 页面大小
        sort: "createTime", // 默认排序字段
        order: "desc", // 默认排序方式
        startDate: "", // 起始时间
        endDate: "", // 终止时间
        serviceType: "RETURN_GOODS",
        orderSn: "",
        memberName: "",
        goodsName: "",
      },
      list: [
        {
          name: "退货管理",
          value: "GOOD",
        },
        {
          name: "退款管理",
          value: "MODERATE",
        },
		{
			name: "换货管理",
			value: "EXCHANGE",
		},
		{
			name: "维修管理",
			value: "REPAIR",
		}
      ],
    };
  },
  methods: {
    onShow() {
      this.afterSaleData = [];
      this.searchForm.pageNumber = 1;
      this.init();
    },
    onReachBottom() {
      this.searchForm.pageNumber++;
      this.init();
    },
    // 点击订单
    handleClickSales(val) {
      uni.navigateTo({
        url: `/pages/order/afterSales/detail?sn=${val.sn}`,
      });
    },
    // 筛选回调
    screened(val) {
      /**
       * 1.循环出相同的字段进行赋值
       * 2.将不同的字段进行赋值
       */
      for (let key in val) {
        this.searchForm[key] != undefined
          ? (this.searchForm[key] = val[key])
          : "";
      }
      val.date[0] ? (this.searchForm.startDate = val.date[0]) : "";
      val.date[1] ? (this.searchForm.endDate = val.date[1]) : "";

      this.load();
    },

 
    changeTabs(index){
      this.current = index
    },
   
 
    // 点击筛选
    handleClickScreen() {
      this.$refs.popup.open();
    },
    load() {
      this.searchForm.pageNumber = 1;
      this.afterSaleData = [];
      this.init();
    },
    async init() {
      uni.showLoading({
        title: "加载中",
      });

      //商品订单
      let res = await afterSaleOrderPage(this.searchForm);
      if (res.data.success) {
        this.afterSaleData.push(...res.data.result.records);
      }

      uni.hideLoading();
    },
  },
};
</script>

<style lang="scss" scoped>
@import "@/components/global.scss";

.global-bottom-col {
  margin: 0;
}
.global-createTime {
  margin: 10rpx 0;
}
.drop-list-tab {
  flex: 3 !important;
}
.drop-list-config {

}

</style>